﻿namespace UnitBox {
	public class VerifySwapConfiguration<T> {

		#region class fields

		private static volatile VerifySwapConfiguration<T> _singletonInstance;

		#endregion


		#region constructors

		private VerifySwapConfiguration() {
			// hidden singleton constructor
		}

		#endregion


		#region properties

		public static VerifySwapConfiguration<T> Instance {
			get {
				if( _singletonInstance == null ) {
					lock( typeof(VerifySwapConfiguration<T>) ) {
						if( _singletonInstance == null )
							_singletonInstance = new VerifySwapConfiguration<T>();
					}
				}
				return _singletonInstance;
			}
		}

		#endregion


		#region public methods

		/// <summary>
		/// Optionally specify that you want to track creations on the configured type, so that you can verify
		/// whether they got invoked in the tested code or not. 
		/// </summary>
		/// <remarks>
		/// Note that specifying this will hold on to all instances created, so this should never get called
		/// in production code. Doing so will effectively create a memory leak which will hold on to all
		/// swapped instances. During testing however this is perfectly acceptable, as it should will only
		/// matter for the lifetime of the test.
		/// </remarks>
		public void Verifiable() {
			// configure the queue to store instances of the configured type
			SwapQueue.RememberSwappedInstances<T>();
		}

		#endregion

	}
}